﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class index : System.Web.UI.Page
{
    string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["xxnewsConnectionString"].ConnectionString;
    SqlConnection sqlcon;
    //SqlCommand sqlcom;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            for (int i =Convert.ToInt32(DateTime.Now.Year) ; i >=2011 ; i--)
            {
                nian.Items.Add(i.ToString());
            }
            for (int i = 1; i <= 12; i++)
            {
                yue.Items.Add(i.ToString());
            }
            nian.SelectedValue = DateTime.Now.Year.ToString();
            //yue.SelectedValue = DateTime.Now.Month.ToString();
        g_bind();
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#D1DDF1'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
           
            //当有编辑列时，避免出错，要加的RowState判断 
            //if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
            //{
            //    ((LinkButton)e.Row.Cells[17].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除这条记录吗?')");
            //}
        }
        if (e.Row.RowIndex != -1)
        {
            int id = e.Row.RowIndex + 1 + GridView1.PageIndex * GridView1.PageSize;
            e.Row.Cells[0].Text = id.ToString();
        }
        this.GridView1.Attributes.Add("bordercolor", "#bbddff");
    }
    protected void DropDownList_sscj_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList_zrbz.Items.Clear();
        DropDownList_zrbz.Items.Add(new ListItem("请选择"));
        DropDownList_zrbz.DataBind();

    }

    public void g_bind()
    {
        Label_tiaojian.Text = "当前选择条件:";
        string sqlstr = "select * FROM cailiaoguanli WHERE 1=1" ;
        if (DropDownList_lei.SelectedValue != "请选择")
        {
            sqlstr += " AND (lei = '" + DropDownList_lei.SelectedValue + "')";
            Label_tiaojian.Text += "类别：" + DropDownList_lei.SelectedValue + "；  ";
        }
        if (nian.SelectedValue != "请选择")
        {
            sqlstr += " AND (nian = '" + nian.SelectedValue + "')";
            Label_tiaojian.Text += nian.SelectedValue + "年；  ";
        }
        if (yue.SelectedValue != "请选择")
        {
            sqlstr += " AND (yue = '" + yue.SelectedValue + "')";
            Label_tiaojian.Text += yue.SelectedValue + "月；  ";
        }
        if (DropDownList_sscj.SelectedValue != "请选择")
        {
            sqlstr += " AND (chejian = '" + DropDownList_sscj.SelectedValue + "')";
            Label_tiaojian.Text += "车间：" + DropDownList_sscj.SelectedValue + "；  ";
        }
        if (DropDownList_zrbz.SelectedValue != "请选择")
        {
            sqlstr += " AND (banzu = '" + DropDownList_zrbz.SelectedValue + "')";
            Label_tiaojian.Text += "班组：" + DropDownList_zrbz.SelectedValue + "；  ";
        }
        if (DropDownList_shenpi.SelectedValue == "车间未审批")
        {
            sqlstr += " AND (zt =1)";
            Label_tiaojian.Text += "审批情况：" + DropDownList_shenpi.SelectedValue + "；  ";
        }
        else if (DropDownList_shenpi.SelectedValue == "段未审批")
        {
            sqlstr += " AND (zt =2)";
            Label_tiaojian.Text += "审批情况：" + DropDownList_shenpi.SelectedValue + "；  ";
        }
        else if (DropDownList_shenpi.SelectedValue == "段已审批未受理")
        {
            sqlstr += " AND (zt =4)";
            Label_tiaojian.Text += "审批情况：" + DropDownList_shenpi.SelectedValue + "；  ";
        }
        else if (DropDownList_shenpi.SelectedValue == "材料科已受理")
        {
            sqlstr += " AND (zt =5)";
            Label_tiaojian.Text += "审批情况：" + DropDownList_shenpi.SelectedValue + "；  ";
        }
        else if (DropDownList_shenpi.SelectedValue == "全部")
        {
            sqlstr += " AND (zt>0)";
            Label_tiaojian.Text += "审批情况：" + DropDownList_shenpi.SelectedValue + "；  ";
        }
        sqlstr += " ORDER BY nian desc,yue desc,c_id desc ";
        if (Label_tiaojian.Text == "当前选择条件:")
        {
            Label_tiaojian.Text = "当前选择条件:无";
        }
        //Response.Write(sqlstr);
        //sqlcon = new SqlConnection(strCon);
        //SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
        //DataSet myds = new DataSet();
        ////sqlcon.Open();
        //myda.Fill(myds, "ganbutiancheng");
        //GridView1.DataSource = myds;
        SqlDataSource1.ConnectionString = strCon;
        SqlDataSource1.SelectCommand = sqlstr;
        GridView1.DataSourceID = SqlDataSource1.ID;
        //GridView1.EnableSortingAndPagingCallbacks = false;
        GridView1.PagerStyle.Font.Size = 10;
        //GridView1.PagerSettings.Position = PagerPosition.TopAndBottom;
        //GridView1.PagerStyle.Font.Bold = true;
        //GridView1.DataBind();
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        g_bind();
    }
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        DropDownList_lei.SelectedValue = "请选择";
        nian.SelectedValue = "请选择";
        yue.SelectedValue = "请选择";
        DropDownList_sscj.SelectedValue = "请选择";
        DropDownList_zrbz.SelectedValue = "请选择";
        DropDownList_shenpi.SelectedValue = "车间未审批";
        nian.SelectedValue = DateTime.Now.Year.ToString();
        //yue.SelectedValue = DateTime.Now.Month.ToString();
        g_bind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        g_bind();
   }
    protected void GridView1_DataBound(object sender, EventArgs e)
    {
        GridViewRow btrow = GridView1.BottomPagerRow;
        Label lb1 = new Label();
        lb1.Text = "当前页码(" + (GridView1.PageIndex + 1) + "/" + GridView1.PageCount + ")";
        if (btrow != null)
        {
            btrow.Cells[0].Controls.Add(lb1);        
        }

    }
    protected void GridView1_PageIndexChanged(object sender, EventArgs e)
    {

    }
}
